package com.tianqu.tms.www.attn.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.www.attn.actionform.AttnCreationInputForm;
import com.tianqu.tms.www.attn.viewhelper.AttnViewhelper;

/**
 * @author zhangxueliang
 * 经办人录入中间跳转action
 */
public class AttnCreationInputDispatchAction extends TmsAction{

	private Logger logger = Logger.getLogger(AttnCreationInputDispatchAction.class);
	private static final String TOCONFIRM = "toConfirm";//保存确认
	private static final String IMGLOAD = "imgLoad";//保存确认
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String forwardPath = null;
		AttnCreationInputForm inputForm = (AttnCreationInputForm)form;
		AttnViewhelper attnViewhelper = new AttnViewhelper();
		attnViewhelper = (AttnViewhelper)uc.getAttribute(TmsConstants.VIEWHELP);
		Member member = Member.getInstance();
		attnViewhelper.setAttnName(inputForm.getAttnName());
		attnViewhelper.setAttnIdCardNo(inputForm.getAttnIdCardNo());
		attnViewhelper.setAccessCardId(inputForm.getAccessCardId());
		attnViewhelper.setAccessCardNo(inputForm.getAccessCardNo());
		attnViewhelper.setAttnAddress(inputForm.getAttnAddress());
		attnViewhelper.setAttnPhone(inputForm.getAttnPhone());
		attnViewhelper.setLoginName(inputForm.getLoginName());
		attnViewhelper.setPassword(inputForm.getPassword());
		attnViewhelper.setCfmPassword(inputForm.getCfmPassword());
		attnViewhelper.setMemberId(inputForm.getMemberId());
		
		attnViewhelper.setMemberList(member.findAllMemInfo());// 会员类型
		//跳转到确认页
		if(inputForm.getSaveInputInfo()!=null && !"".equals(inputForm.getSaveInputInfo()))
		{
			forwardPath = TOCONFIRM;
		}else if(!StringUtil.isNullOrBlank(inputForm.getImgUpLoad1())){
			forwardPath = IMGLOAD;
		}
		uc.setAttribute(TmsConstants.VIEWHELP, attnViewhelper);
		request.setAttribute(TmsConstants.VIEWHELP, attnViewhelper);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(forwardPath);
	}

}
